package com.steptime.framework.spring.aop.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyJdkProxy implements InvocationHandler {

    private UserDao object;

    public MyJdkProxy(UserDao object){
        this.object = object;
    }

    public UserDao createProxy(){
        UserDao proxy = (UserDao)Proxy.newProxyInstance(UserDaoImpl.class.getClassLoader(),
                UserDaoImpl.class.getInterfaces(), this);
        return proxy;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if("getUserInfo". equals(method. getName())){
            System.out.println("==============代理增强============");
            return method.invoke(object,args);
        }
        return method.invoke(object,args);
    }
}
